package cn.iocoder.yudao.module.self.mq.service;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.self.controller.admin.student.vo.StudentSaveReqVO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.UUID;

@Service
public class MyRabbitMqProductService {

    @Autowired
    RabbitTemplate rabbitTemplate;
    public String sendDirectMessage(StudentSaveReqVO createReqVO){
        HashMap <String,String> map=new HashMap<>();
        map.put("messageId", String.valueOf(UUID.randomUUID()));
        map.put("messageData","message: test message,hello!");
        map.put("messageData2", JsonUtils.toJsonString(createReqVO));
        map.put("createTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        rabbitTemplate.convertAndSend("TestDirectExchange","TestDirectRouting",map);
        return "ok";
    }

    public String sendTopicMessage1(StudentSaveReqVO createReqVO){
        HashMap <String,String> map=new HashMap<>();
        map.put("messageId", String.valueOf(UUID.randomUUID()));
        map.put("messageData","message M A N");
        map.put("createTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        rabbitTemplate.convertAndSend("topicExchange","topic.man",map);
        return "ok";
    }

    public String sendTopicMessage2(StudentSaveReqVO createReqVO){
        HashMap <String,String> map=new HashMap<>();
        map.put("messageId", String.valueOf(UUID.randomUUID()));
        map.put("messageData","message W O M A N");
        map.put("createTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        rabbitTemplate.convertAndSend("topicExchange","topic.woman",map);
        return "ok";
    }

    public String sendTopicMessage3(StudentSaveReqVO createReqVO){
        HashMap <String,String> map=new HashMap<>();
        map.put("messageId", String.valueOf(UUID.randomUUID()));
        map.put("messageData","message O T H E R");
        map.put("createTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        rabbitTemplate.convertAndSend("topicExchange","topic.other",map);
        return "ok";
    }

    public String sendTopicMessage4(StudentSaveReqVO createReqVO){
        HashMap <String,String> map=new HashMap<>();
        map.put("messageId", String.valueOf(UUID.randomUUID()));
        map.put("messageData","message O T H E R - 2");
        map.put("createTime", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        rabbitTemplate.convertAndSend("topicExchange","topic.other.2",map);
        return "ok";
    }
}
